﻿using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using XGE;
using Microsoft.Xna.Framework;

namespace XGE.ComponentSystem
{
    public class ComponentCollection : Collection<IDrawableObject>
    {
        private ICoreGame game;
        private bool Initialized = false;
        public ComponentCollection(ICoreGame game)
        {
            this.game = game;
        }
        public void AddComponent(IDrawableObject Object)
        {
            
            Object.AddGame(game);
            this.Add(Object);
            if(Initialized)
                this.Last().Initialize();
        }
        public void RemoveComponent(IDrawableObject Object)
        {
            this.Remove(Object);
        }
        public void Initialize()
        {
            for (int i = 0; i < Count; i++)
            {
                this[i].Initialize();
            }
            Initialized = true;
        }
        public void LoadContent()
        {
            
            for (int index = 0; index < Count; index++)
            {
                this[index].LoadContent();
            }
        }
        public void Update(GameTime gameTime)
        {
            for (int index = 0; index < Count; index++)
            {
                if(this[index].isEnabled)
                    this[index].Update(gameTime);
            }
        }
        public void Draw(GameTime gameTime)
        {
            for (int index = 0; index < Count; index++)
            {
                if (this[index].isEnabled)
                    this[index].Draw(gameTime);
            }
        }
    }
}
